Skip to content

Conversation

@kilink
Copy link
Contributor

@kilink kilink commented Nov 13, 2025

The Spliterators returned by values, entrySet, and keySet incorrectly reported the SIZED characteristic, instead of CONCURRENT. This could lead to bugs when the map is concurrently modified during a stream operation.

For keySet and values, the incorrect characteristics are inherited from AbstractMap, so to rectify that the respective methods are overridden and custom collections are provided that report the correct Spliterator characteristics.

The same sort of bug was reported and fixed in Caffeine, and the issue seems to exist in several other ConcurrentMap implementations in the wild.

The Spliterators returned by values, entrySet, and keySet incorrectly reported
the SIZED characteristic, instead of CONCURRENT. This could lead to bugs when
the map is concurrently modified during a stream operation.

For keySet and values, the incorrect characteristics are inherited from
AbstractMap, so to rectify that the respective methods are overridden and
custom collections are provided that report the correct Spliterator
characteristics.

Signed-off-by: Patrick Strawderman <pstrawderman@netflix.com>
@kilink kilink force-pushed the concurrent-reference-hash-map-fix-spliterators branch from aefaa72 to e4b7baf Compare November 13, 2025 20:49
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Nov 13, 2025
@sbrannen sbrannen added the in: core Issues in core modules (aop, beans, core, context, expression) label Nov 15, 2025
@sbrannen sbrannen self-assigned this Nov 15, 2025
@jhoeller
Copy link
Contributor

Good point, let's fix this for 7.0.1. This is also worth backporting to 6.2.14.

@sbrannen sbrannen added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Nov 17, 2025
@sbrannen sbrannen added this to the 7.0.1 milestone Nov 17, 2025
@sbrannen sbrannen added the for: backport-to-6.2.x Marks an issue as a candidate for backport to 6.2.x label Nov 17, 2025
@sbrannen sbrannen changed the title Fix Spliterator characteristics in ConcurrentReferenceHashMap Fix Spliterator characteristics in ConcurrentReferenceHashMap Nov 17, 2025
@sbrannen sbrannen added status: backported An issue that has been backported to maintenance branches and removed for: backport-to-6.2.x Marks an issue as a candidate for backport to 6.2.x labels Nov 17, 2025
@sbrannen sbrannen closed this in ed75906 Nov 17, 2025
sbrannen added a commit that referenced this pull request Nov 17, 2025
sbrannen pushed a commit that referenced this pull request Nov 17, 2025
The Spliterators returned by values, entrySet, and keySet incorrectly
reported the SIZED characteristic, instead of CONCURRENT. This could
lead to bugs when the map is concurrently modified during a stream
operation.

For keySet and values, the incorrect characteristics are inherited from
AbstractMap, so to rectify that the respective methods are overridden,
and custom collections are provided that report the correct Spliterator
characteristics.

Closes gh-35817

Signed-off-by: Patrick Strawderman <pstrawderman@netflix.com>

(cherry picked from commit ed75906)
sbrannen added a commit that referenced this pull request Nov 17, 2025
See gh-35817

(cherry picked from commit 09a8bbc)
@sbrannen
Copy link
Member

This has been merged into main and backported to 6.2.x.

Thanks 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in: core Issues in core modules (aop, beans, core, context, expression) status: backported An issue that has been backported to maintenance branches type: enhancement A general enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants